package com.example.mode.adapter;



import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

public class ViewPagerAdapter extends FragmentStateAdapter {
    String[] titleArr;
    List<Fragment> fragmentList;
    public ViewPagerAdapter(FragmentActivity fragmentActivity,
                            List<Fragment> list, String[] titleArr) {
        super(fragmentActivity);
        fragmentList = list;
        this.titleArr = titleArr;
    }
//页面位置 数量 标题
    @Override
    public Fragment createFragment(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getItemCount() {
        return fragmentList.size();
    }
    public CharSequence getTitle(int position){
        return titleArr[position];
    }
}
